﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HotelManagement.DAO;
using HotelManagement.DTO;


namespace HotelManagement.BLO
{
    class CustomerBLO
    {
        private CustomerDAO dao;

        public CustomerBLO()
        {
            dao = new CustomerDAO();
        }

        public DataTable Select()
        {
            return this.dao.Select();
        }
        public DataTable SelectWithType()
        {
            return this.dao.SelectWithType();
        }
        public bool Insert(CustomerDTO customer)
        {
            return this.dao.Insert(customer);
        }

        public bool Update(CustomerDTO customer)
        {
            return this.dao.Update(customer);
        }
        public bool Delete(CustomerDTO customer)
        {
            return this.dao.Delete(customer);
        }
        public int SelectLastInsertID()
        {
            return dao.SelectLastInsertID();
        }
        public bool CheckExist(string pIDNo)
        {
            if (pIDNo=="")
            {
                return false;
            }
            DataTable tbl = this.Select();
            foreach (DataRow row in tbl.Rows)
            {
                if (row["IDNo"].ToString()==pIDNo)
                {
                    return true;
                }
            }
            return false;
        }
        public CustomerDTO GetCustomerFromID(int pID)
        {
            if (pID==0)
            {
                return null;
            }
            DataTable tbl = this.Select();
            foreach (DataRow row in tbl.Rows)
            {
                if (int.Parse(row["CustomerID"].ToString())==pID)
                {
                    CustomerDTO cust = new CustomerDTO();
                    cust.CustomerID = pID;
                    cust.Name=row["Name"].ToString();
                    cust.Gender = row["Gender"].ToString();
                    cust.IDNo_Passport = row["IDNo"].ToString();
                    cust.CusTypeID = int.Parse(row["CusTypeID"].ToString());
                    cust.BirthYear = DateTime.Parse(row["Birth"].ToString());
                    cust.PhoneNumber = row["PhoneNumber"].ToString();
                    cust.Address = row["Address"].ToString();
                    cust.Occupation = row["Occupation"].ToString();
                    cust.Nationality = row["Nationality"].ToString();
                    return cust;
                }
            }
            return null;
        }
    }
}
